/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vigas.componentes;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;

/**
 *
 * @author Lidiany
 */
public class CargaAplicada implements Carga{

     private Point pontoMarcadoNaviga;
     private float valorDaCarga;
     private Path2D.Double arrow = criarSeta();

    public CargaAplicada() {
    }


     public void desenharCarga(Graphics g) {
         double theta = 1.5707963267948966;

            Graphics2D g2 = (Graphics2D) g.create();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);           
                    
            AffineTransform at = AffineTransform.getTranslateInstance(pontoMarcadoNaviga.x, pontoMarcadoNaviga.y - 25);
            at.rotate(theta);
            at.scale(2.0, 2.0);
            Shape shape = at.createTransformedShape(arrow);
            g2.setPaint(Color.blue);
            g2.draw(shape);

            //g2.setColor(Color.red);
            g2.drawString(String.valueOf(valorDaCarga) + " kN",
                    pontoMarcadoNaviga.x-2, pontoMarcadoNaviga.y - 71);
            g2.dispose();

     }

     private Path2D.Double criarSeta() {
        int length = 30;
        int barb = 8;
        double angle = Math.toRadians(20);
        Path2D.Double path = new Path2D.Double();
        path.moveTo(-length / 2, 0);
        path.lineTo(length / 2, 0);
        double x = length / 2 - barb * Math.cos(angle);
        double y = barb * Math.sin(angle);
        path.lineTo(x, y);
        x = length / 2 - barb * Math.cos(-angle);
        y = barb * Math.sin(-angle);
        path.moveTo(length / 2, 0);
        path.lineTo(x, y);
        return path;
    }

    public Point getPontoMarcadoNaviga() {
        return pontoMarcadoNaviga;
    }

    public void setPontoMarcadoNaviga(Point pontoMarcadoNaviga) {
        this.pontoMarcadoNaviga = pontoMarcadoNaviga;
    }

    public float getValorDaCarga() {
        return valorDaCarga;
    }

    public void setValorDaCarga(float valorDaCarga) {
        this.valorDaCarga = valorDaCarga;
    }

     public void alterarCoordX(int x){        
         pontoMarcadoNaviga.x = x;
        
     }

     public float getPosicaoRelativa(Viga v){
         return  (float)(pontoMarcadoNaviga.x - v.getInicio())/100 ;
     }
}
